buildscript {
    ext.kotlin_version = '2.0.0'
    ext.klogging_version = '3.0.5'
    ext.jacksonKt_version = '2.17.1'
    ext.libVersion = '2024.0.7'
    repositories {
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.23.6"
        classpath "org.jlleitschuh.gradle:ktlint-gradle:12.1.1"
    }
}

plugins {
    id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
//    id "org.jlleitschuh.gradle.ktlint-idea" version "11.6.1"
    id "org.jlleitschuh.gradle.ktlint" version "12.1.1"
}

group = 'io.github.adven27'
version = libVersion

allprojects {
    apply plugin: "org.jlleitschuh.gradle.ktlint"
    repositories {
        mavenCentral()
    }
}

subprojects {
//    apply plugin: "io.gitlab.arturbosch.detekt"
    apply plugin: 'kotlin'
    apply plugin: 'java'
    apply plugin: 'idea'
    apply plugin: "org.jlleitschuh.gradle.ktlint"

    repositories {
        mavenCentral()
    }

    ktlint {
        debug = true
        verbose = true
        android = false
    }

    group = 'io.github.adven27'
    version = libVersion

    sourceCompatibility = 17
    targetCompatibility = 17
    compileJava.options.encoding = 'utf-8'
    compileTestJava.options.encoding = 'utf-8'

    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
        kotlinOptions {
            freeCompilerArgs += '-Xjsr305=strict'
            jvmTarget = '17'
        }
    }

    dependencies {
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
        runtimeOnly 'com.pinterest:ktlint:0.47.1'
    }

    test {
        systemProperty "user.timezone", "Europe/Moscow"
        testLogging.showStandardStreams = true
        testLogging.exceptionFormat = 'full'
        testLogging.events('FAILED', 'PASSED')
        maxParallelForks = Runtime.runtime.availableProcessors()
    }
}

tasks.register('publishMaven') {
    dependsOn ":exam-core:publishToSonatype"
    dependsOn ":exam-db:publishToSonatype"
    dependsOn ":exam-ws:publishToSonatype"
    dependsOn ":exam-mq:publishToSonatype"
    dependsOn ":exam-mq-rabbit:publishToSonatype"
    dependsOn ":exam-mq-kafka:publishToSonatype"
    dependsOn ":exam-mq-ibmmq:publishToSonatype"
    dependsOn ":exam-mq-redis:publishToSonatype"
//    dependsOn ":exam-ui:publishToSonatype"
    dependsOn ":exam-ms:publishToSonatype"
//    dependsOn ":exam-nosql:publishToSonatype"
//    dependsOn ":exam-nosql-mongo:publishToSonatype"
//    dependsOn ":exam-nosql-elastic:publishToSonatype"
}

nexusPublishing {
    repositories {
        sonatype {
            nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
            snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
        }
    }
}
